/*
 * jlb
 */
package com.jlb.core.exceptions;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * 基本异常类
 *
 * @author lixin 2017-08-03 17:46
 */
public class BaseException extends RuntimeException implements Serializable {
    private static final Logger logger = LoggerFactory.getLogger(BaseException.class);

    public BaseException(BaseExceptionEnum exceptionMessage) {
        super(exceptionMessage.toString());
        logger.error("系统发生异常[{}]", exceptionMessage.toString());
    }

    public BaseException(BaseExceptionEnum exceptionMessage, Object... params) {
        super(exceptionMessage.toString());
        logger.error("系统发生异常[{}],参数为[{}]", exceptionMessage.toString(), JSON.toJSONString(params));
    }


    public BaseException(String message) {
        super(message);
        logger.error("系统发生异常[{}]", message);
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
        logger.error("系统发生异常[{}],异常为[{}]", message, cause);
    }


    /*异常信息定义*/
    public enum BaseExceptionEnum {

        //-----------------系统异常定义 [9000~9499]--------------------------
        Server_Error("9999", "服务器异常"),
        Success("0000", "成功"),
        State_Error("9002", "State error"),
        Ilegal_Param("9003", "参数不能为空"),
        Empty_Param("9004", "参数不能为空"),
        Exists("9005", "数据已存在"),
        Result_Not_Exist("9006", "查询的数据不存在"),
        Session_Error("9001", "登录超时，请重新登录"),
        PARAMISINVALID("9007", "无效的参数"),

        //-----------------上传文件异常定义[9500~9599]--------------------------
        Build_Exist("9500", "build exist"),

        //-----------------矿机异常定义[8000~8099]--------------------------
        Miner_Stop("8000", "矿机已经停机，请重新激活"),
        Miner_Not_Exist("8001", "您还没有矿机"),
        Mill_Not_Exist("8002", "矿机不存在"),
        Miner_Not_Sales("8003", "矿机不在出售中"),
        Miner_Normal("8004", "矿机工作中"),
        Already_Buy("8005", "您已购买过矿机"),
        Just_Allow_Upgrade("8006", "请选择高功率矿机"),
        Not_Need_Re_Cast_Miner("8007", "您的矿机处于工作状态，无需复投"),

        //-----------------金兰宝异常异常定义[7000~7099]--------------------------
        Jlb_Not_Exist("7000", "金兰宝不存在"),
        Jlb_State_Error("7001", "金兰宝尚未挖掘到"),
        Jlb_Frozen_Error("7002", "金兰宝账户暂时无法使用"),
        Jlb_Not_Enough_Error("7003", "金兰宝账户余额不足"),
        Invite_Jlb_Not_Enough_Error("7004", "邀请人金兰宝余额不足"),

        //-----------------矿石异常异常定义[6000~7099]--------------------------
        Ore_Not_Exist("6000", "矿石不存在"),
        Ore_Not_Enough_Error("6001", "矿石量不足"),
        Ore_Working("6002", "无需复投动态收益"),


        //-----------------账户异常定义[1051~1070]--------------------------
        Job_Token_Verifier_Failed("1051", "调度token验证失败"),

        //-----------------账户异常定义[1000~1050]--------------------------
        Account_Error("1000", "账户或密码错误"),
        User_Error("1001", "账户不存在"),
        Not_Is_Leader("1002", "该用户不是领导人，不能转入激活码"),
        User_Not_Active("1003", "该用户不是激活状态"),
        Pin_Password_Is_Error("1004", "输入的交易密码不正确"),
        Not_Allow_Connection("1005", "该账户无法进行关联"),
        Can_Not_Connection("1006", "您不是该账户的推荐人，无法进行关联"),
        Not_Allow_Transfer("1007", "您没有权限转账到该账户"),
        Not_Allow_Transfer_Yourself("1008", "不能转账到自己账户"),
        Star_Is_Error("1009", "星级不存在，请联系管理员"),
        User_Is_Exist("1010", "账号已存在"),
        SubAccount_Allow_Bind("1011", "该账户已经被绑定"),

        //-----------------激活码异常[1100~1200]--------------------------
        Active_State_Error("1100", "该激活码不是可使用状态"),
        Active_Not_Enough_Error("1101", "激活码不充足"),;


        public String errCode;//错误编码
        public String error;//错误信息

        //信息提示：不存在
        private static String not_exist(String arg) {
            return arg + " does not exist";
        }

        //信息提示：已经存在
        private static String already_exist(String arg) {
            return arg + " already exists";
        }

        //信息提示：添加失败
        private static String add_failed(String arg) {
            return "add " + arg + " failed";
        }

        BaseExceptionEnum(String errCode, String error) {
            this.errCode = errCode;
            this.error = error;
        }

        @Override
        public String toString() {
            return "{code:" + errCode + ", error:\"" + error + "\"}";
        }

    }
}
